/*
* 人员选择
* */

import 'package:center_beijing/api/task_api.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/models/selectItem.dart';
import 'package:center_beijing/widgets/checkbox_widget.dart';
import 'package:center_beijing/widgets/search_widget.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SelectPerson extends StatefulWidget {
  @override
  _SelectPersonState createState() => _SelectPersonState();
}

class _SelectPersonState extends State<SelectPerson>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List allItemList = [];
  var type = Get.arguments;

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getNodesPersons();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

/*
  * 获取整改人
  * */
  getNodesPersons() async {
    var result = await getNodeUser({
      'projectSectionId': GlobalConfig.selectFactory.tag,
      'issueType': type,
    });
    if (result != null && result.length > 0) {
      this.setState(() {
        allItemList = result;
      });
    }
    LogUtil.d(result);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('人员选择'),
        ),
        body: Container(
          color: Styles.MainBackgroundColor,
          padding: EdgeInsets.fromLTRB(
              0, 0, 0, MediaQuery.of(context).padding.bottom + 70),
          child: SingleChildScrollView(
            child: Column(
              children: this.allItemList.map<Widget>((item) {
                return GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () {
                    this.setState(() {
                      item['selected'] =
                          item['selected'] == null ? true : !item['selected'];
                    });
                  },
                  child: Container(
                    padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8, Styles.spacing16, Styles.spacing8),
                    child: Row(
                      children: [
                        Container(
                          padding:
                              EdgeInsets.fromLTRB(0, 0, Styles.spacing8, 0),
                          child: Image.asset(
                            (item['selected'] != null && item['selected'])
                                ? "assets/images/group_selected.png"
                                : "assets/images/group_select.png",
                            width: 20.w,
                            height: 20.h,
                            fit: BoxFit.contain,
                          ),
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              item['name'],
                              style: TextStyle(
                                  color: Styles.DetailColor,
                                  fontSize: Styles.Middle16Font),
                            ),
                            Text(
                              item['mobile'],
                              style: TextStyle(
                                  color: Styles.DetailColor,
                                  fontSize: Styles.Middle16Font),
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                );
              }).toList(),
            ),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Container(
          padding: EdgeInsets.fromLTRB(
              Styles.spacing8, Styles.spacing8, Styles.spacing8, 10),
          child: Container(
            decoration: new BoxDecoration(
              //背景
              color: Styles.BlueColor,
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
            ),
            child: FlatButton(
              disabledColor: Styles.SelectColor,
              onPressed: () {
                List list = [];
                this.allItemList.forEach((element) {
                  if(element['selected']!=null&&element['selected']){
                    list.add(element);
                  }
                });
                Get.back(result: list);
              },
              child: Container(
                height: Styles.MainButtonHeight,
                alignment: Alignment.center,
                child: Text(
                  '确定',
                  style: TextStyle(
                      fontSize: Styles.MainButtonTextFont, color: Colors.white),
                ),
              ),
            ),
          ),
        ));
  }
}
